let ENTRY_MAPPING = process.env

async function fetchProEntry() {
  const response = await fetch('/configuration/entrypoint') // 获取线上子应用配置
  const result = await response.json()
  return result
}

function initEntry() {
  return [
    {
      name: 'kgConstructionApp', // app name registered
      entry: ENTRY_MAPPING.VUE_APP_KG_CONSTRUCTION || '',
      container: '#microApp',
      activeRule: '/app/kgconstruct/project/:id',
      props: {
        routerBase: '/app/kgconstruct',
      },
    },
    {
      name: 'kgApplicationApp', // app name registered
      entry: ENTRY_MAPPING.VUE_APP_KG_APPLICATION || '',
      container: '#microApp',
      activeRule: '/app/knowledge/project/:id',
      props: {
        routerBase: '/app/knowledge',
      },
    },
    {
      name: 'kgApplicationPublish', // app name registered
      entry: ENTRY_MAPPING.VUE_APP_KG_APPLICATION || '',
      container: '#microApp',
      activeRule: '/app/knowledge/publish/:token',
      props: {
        routerBase: '/app/knowledge',
      },
    },
  ]
}

// 获取子应用配置
export function getMicroAppEntryList() {
  if (process.env.NODE_ENV === 'production') {
    // 生产环境
    return new Promise((resolve) => {
      fetchProEntry().then((value) => {
        ENTRY_MAPPING = value
        const result = initEntry()
        resolve(result)
      })
    })
  }
  return new Promise((resolve) => {
    ENTRY_MAPPING = process.env
    resolve(initEntry())
  })
}

export default {}
